package com.bi.autotest.operations.payprocessoperation;

import com.auto.base.OperateAppium;
import com.bi.autotest.pages.payprocesspage.NewMyLoginPage;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

public class NewMyLoginOperation extends OperateAppium {
    private NewMyLoginPage newMyLoginPage;

    public NewMyLoginOperation(AndroidDriver androidDriver) {
        super(androidDriver);

        newMyLoginPage = new NewMyLoginPage(androidDriver);
    }


    /**
     * 进入登录页面的操作
     *
     * @return
     */
    public boolean LoginPre() {
        exePre();
        boolean isLoginPage = newMyLoginPage.isLoginPage();
        return isLoginPage;
    }


    public void clearText() {
        //先去清空输入框的内容
        clearText(newMyLoginPage.getNameInputAreaH5());
        clearText(newMyLoginPage.getPassWordInputAreaH5());
    }

    public boolean login(String name, String pass) {
        //点击登录并收款的按钮
        AndroidElement ae = newMyLoginPage.getToLoginButton();//莫名其妙的失败
        ae.click();
        sleep(3000);
        input(newMyLoginPage.getNameInputAreaH5(), name);
        input(newMyLoginPage.getPassWordInputAreaH5(), pass);
        clickView(newMyLoginPage.getLoginButton());
        sleep(3000);
        boolean isSucess = newMyLoginPage.isLoginSuccess();
        AndroidElement storeHYD = newMyLoginPage.getStoreHYD();
        storeHYD.click();
        AndroidElement sellerLogin = newMyLoginPage.getSellerLogin();
        sellerLogin.click();
        switchAppContext();
        //点击关闭按钮
        pressCloseButton();
        sleep(2000);
        return isSucess;
    }

    //进入登录页面
    public void exePre() {
        sleep(5000);
        driver.findElementByXPath("//android.widget.TextView[@text='我']").click();
        System.out.println("点我");
        sleep(2000);
        driver.findElementByXPath("//android.widget.TextView[@text='收藏']").click();
        sleep(2000);
        toQRCodePage();
    }

    //缓存登录页面
    public void exePreCache() {
        sleep(5000);
        //  AndroidElement ae= (AndroidElement) driver.findElementByXPath("//android.widget.TextView[@text='我']");
        driver.findElementByXPath("//android.widget.TextView[@text='我']").click();
        System.out.println("点我");
        sleep(2000);
        driver.findElementByXPath("//android.widget.TextView[@text='收藏']").click();
        sleep(2000);
        intoReceiptCode();
    }
    public boolean LoginPreNew() {
        exePreCache();
        boolean isSuccessPage = newMyLoginPage.isCacheLoginSuccessPage();
        return isSuccessPage;
    }

    public void exePreNew() {
        sleep(5000);
        AndroidElement ae = (AndroidElement) driver.findElementByName("女亭");
        ae.click();
        sleep(2000);
        AndroidElement ae1 = (AndroidElement) driver.findElementById("com.tencent.mm:id/apz");
        ae1.click();
    }

    public void selectGG() {
        newMyLoginPage.getGGButton().click();
        newMyLoginPage.getConfirmLoginButton().click();
        sleep(2000);
    }

    //我的收藏进入收款码页面
    public void intoReceiptCode() {
        //sleep(2000);
        //收藏页面的链接
        AndroidElement ae = newMyLoginPage.getReceivablesCode();
        ae.click();
        sleep(2000);
        //进入后的链接
        AndroidElement ael = newMyLoginPage.getReceivablesCode();
        ael.click();
        sleep(5000);
        System.out.println("打开收款码h5");
    }
    public void toQRCodePage() {
        driver.findElementByXPath("//android.widget.TextView[@text='收款码']").click();
        sleep(5000);
        print("打开收款码页面");
        switchH5_C_W(newMyLoginPage.TO_LOGIN_SUCCESSPAGE);

    }

}
